﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace BoxDiary
{

    static class IniOperator
    {
        //声明系统API 用于读写ini配置项
        [DllImport("kernel32")]
        internal static extern int GetPrivateProfileString(
            string lpAppName, string lpKeyName, string lpDefault,
            StringBuilder lpReturnedString, int nSize, string lpFileName
            );
        [DllImport("kernel32")]
        internal static extern int WritePrivateProfileString(
            string lpApplicationName, string lpKeyName,
            string lpString, string lpFileName
            );

        public static void Write(
               string section, string key, string value, string path
        )
        {
            WritePrivateProfileString(section, key, value, path);
        }

        public static string Read(string section, string key, string path)
        {
            StringBuilder sb = new StringBuilder(255);
            GetPrivateProfileString(section, key, "", sb, 255, path);
            return sb.ToString();
        }
    }
}
